---
title: PasswordInput
description: "`PasswordInput` is a component that allows users to input passwords with a visibility toggle."
storybook: components-passwordinput--basic
source: components/password-input
style: components/password-input/password-input.style.ts
---

```tsx preview
<PasswordInput placeholder="Your Password" />
```

## Usage

:::code-group

```tsx [package]
import { PasswordInput, StrengthMeter } from "@yamada-ui/react"
```

```tsx [alias]
import { PasswordInput, StrengthMeter } from "@/components/ui"
```

```tsx [monorepo]
import { PasswordInput, StrengthMeter } from "@workspaces/ui"
```

:::

```tsx
<PasswordInput />
<StrengthMeter />
```

### Change Variants

```tsx preview
<VStack>
  <For each={["outline", "filled", "flushed"]}>
    {(variant) => (
      <PasswordInput
        key={variant}
        variant={variant}
        placeholder={toTitleCase(variant)}
      />
    )}
  </For>
</VStack>
```

### Change Size

```tsx preview
<VStack>
  <For each={["xs", "sm", "md", "lg"]}>
    {(size) => (
      <PasswordInput key={size} size={size} placeholder={`Size (${size})`} />
    )}
  </For>
</VStack>
```

### Change Color Scheme

```tsx preview
<VStack>
  <For each={["success", "warning"]}>
    {(colorScheme) => (
      <PasswordInput
        key={colorScheme}
        colorScheme={colorScheme}
        placeholder={toTitleCase(colorScheme)}
      />
    )}
  </For>
</VStack>
```

### Default Visible

To display the value by default, set `defaultVisible` to `true`.

```tsx preview
<PasswordInput
  defaultValue="password"
  defaultVisible
  placeholder="Your Password"
/>
```

### Show Strength Meter

To display the strength meter, use `StrengthMeter`.

```tsx preview functional client
const [value, setValue] = useState("Password")

const getStrength = (password: string): number => {
  let strength = 0

  if (password.length >= 8) strength++
  if (/[A-Z]/.test(password)) strength++
  if (/[0-9]/.test(password)) strength++
  if (/[^A-Za-z0-9]/.test(password)) strength++

  return strength
}

return (
  <VStack>
    <PasswordInput
      placeholder="Your Password"
      value={value}
      onChange={(e) => setValue(e.target.value)}
    />

    <StrengthMeter value={getStrength(value)} />
  </VStack>
)
```

### Change Border Color

To change the border color, set `focusBorderColor` or `errorBorderColor` to the color.

```tsx preview
<VStack>
  <PasswordInput
    focusBorderColor="green.500"
    placeholder="Custom Border Color"
  />
  <PasswordInput
    errorBorderColor="orange.500"
    invalid
    placeholder="Custom Border Color"
  />
</VStack>
```

### Change Placeholder Color

To change the placeholder color, set `_placeholder` to the color.

```tsx preview
<PasswordInput
  placeholder="Custom Placeholder"
  _placeholder={{ color: "blue.500" }}
/>
```

### Disable

To disable, set `disabled` to `true`.

```tsx preview
<VStack>
  <For each={["outline", "filled", "flushed"]}>
    {(variant) => (
      <PasswordInput
        key={variant}
        variant={variant}
        disabled
        placeholder={toTitleCase(variant)}
      />
    )}
  </For>
</VStack>
```

### Read-Only

To make read-only, set `readOnly` to `true`.

```tsx preview
<VStack>
  <For each={["outline", "filled", "flushed"]}>
    {(variant) => (
      <PasswordInput
        key={variant}
        variant={variant}
        readOnly
        placeholder={toTitleCase(variant)}
      />
    )}
  </For>
</VStack>
```

### Invalid

To make invalid, set `invalid` to `true`.

```tsx preview
<VStack>
  <For each={["outline", "filled", "flushed"]}>
    {(variant) => (
      <PasswordInput
        key={variant}
        variant={variant}
        invalid
        placeholder={toTitleCase(variant)}
      />
    )}
  </For>
</VStack>
```

### Customize Icon

To customize icons, set `on` and `off` of `visibilityIcon` to `ReactNode`.

```tsx preview
<PasswordInput
  placeholder="Your Password"
  visibilityIcon={{ off: <SmileIcon />, on: <FrownIcon /> }}
/>
```

### Control

```tsx preview functional client
const [visible, setVisible] = useState(true)

return (
  <VStack>
    <Text>Password visibility: {visible ? "show" : "hide"}</Text>

    <PasswordInput
      placeholder="Your Password"
      visible={visible}
      onVisibleChange={setVisible}
    />
  </VStack>
)
```

## Props

<PropsTable name="password-input" />

## Accessibility

Currently, this section is being updated due to the migration of v2.
